package com.kstech.mp3604.fragments

import com.kstech.mp3604.base.BaseDialogFragment
import com.kstech.mp3604.bean.Data2
import com.kstech.mp3604.bean.Data3
import com.kstech.mp3604.bean.Data5
import com.kstech.mp3604.bean.Data6
import com.kstech.mp3604.bean.StackCoordinate
import com.kstech.mp3604.databinding.FragmentDialogTestSocketBinding
import com.kstech.mp3604.manager.socket.SocketManager

/**
 * 设置按钮-socket测试界面
 */
class DialogTestSocketFragment(val stack: StackCoordinate) :
    BaseDialogFragment<FragmentDialogTestSocketBinding>(FragmentDialogTestSocketBinding::inflate) {
    override fun onInitView() {
        binding.apply {
            button.setOnClickListener {
                val x = setX.text.toString().trim().toInt()
                val y = setY.text.toString().trim().toInt()
                val z = setZ.text.toString().trim().toInt()
                SocketManager.sendSocketData(
                    "heartbeat", Data2(
                        "192.168.32.1", 34, x, y, z, 100, 2, 1, 2
                    )
                )
            }
            button1.setOnClickListener {
                SocketManager.sendSocketData(
                    "task/start", Data3(
                        stack.taskData.transferOrderNo, 1, stack.taskData.taskId
                    )
                )
            }
            //堆码完成
            button2.setOnClickListener {
                val x = setX.text.toString().trim().toInt()
                val y = setY.text.toString().trim().toInt()
                val z = setZ.text.toString().trim().toInt()
                val weight = setWeight.text.toString().trim().toDouble()
//                SocketManager.sendSocketData(
//                    "task/end", Data4(
//                        34,
//                        5,
//                        weight,
//                        x,
//                        y,
//                        z,
//                        TimeUtil.getDateTimeStr(),
//                        mTask.taskId,
//                        mTask.operateType,
//                        mTask.transferOrderNo,
//                        "192.169.1.6",
//                        Global.WARE_HOUSE_ID
//                    )
//                )
            }
            //吊起完成
            button3.setOnClickListener {
                val x = setX.text.toString().trim().toInt()
                val y = setY.text.toString().trim().toInt()
                val z = setZ.text.toString().trim().toInt()
                val weight = setWeight.text.toString().trim().toDouble()
//                SocketManager.sendSocketData(
//                    "task/end", Data4(
//                        34,
//                        6,
//                        weight,
//                        x,
//                        y,
//                        z,
//                        TimeUtil.getDateTimeStr(),
//                        mTask.taskId,
//                        mTask.operateType,
//                        mTask.transferOrderNo,
//                        "192.169.1.6",
//                        Global.WARE_HOUSE_ID
//                    )
//                )
            }
            button10.setOnClickListener {
                SocketManager.sendSocketData(
                    "task/end", Data5(1, 1, "LiftSpeed", "超速", "备注...", 1)
                )
            }
            sendSettingAck.setOnClickListener {
                val whId = binding.setWareHouseId.text.toString().trim()
                if (whId.isNullOrEmpty()) {
                    showSnackBar("请输入仓库id，不能为空")
                    return@setOnClickListener
                }
                SocketManager.sendSocketData(
                    "config", Data6(whId)
                )
                showSnackBar("发送成功")
            }
        }
    }


}